import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.0
import Http 1.0
Rectangle{

    property string username:""
    property string password:""
    property string errorInfo :""
    anchors.fill: parent
    color:"#ffffff"



    HttpUtils{

        id:http
    }

    //用户登录
    function userLogin(username,password){

        function onReply(reply){

            console.log(reply)
            console.log("请求结束")

            http.onReplySignal.disconnect(onReply)
        }
        http.onReplySignal.connect(onReply)
        http.postApi(`/lris/user/login`,{username:username,password:password})
    }

        Rectangle{
            id:usernamefrom
            anchors.top: parent.top
//            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                anchors.fill: parent
            height: parent.height*0.55
            width: parent.width
            color:"#ffffff"





            Button{
                id:erweima
                anchors.top:password.bottom
                anchors.right: password.right
                height:50
                width:50
                icon{
                    height:50
                    width:50
                    source:"qrc:/images/erweima"
                    color:"#4f4f4f"
                }
                background:Rectangle{
                    anchors.fill: parent
                    color:"#ffffff"
                    MouseArea{
                        anchors.fill: parent;
                        hoverEnabled: true;
                        onEntered: {    //鼠标移入
                            erweima.icon.color = "#2775ff"
                            //背景
                        }
                        onExited: {
                            //移出icon颜色
                            erweima.icon.color = "#4f4f4f"
                            //移出背景色
                        }

                    }
                }
            }

            Text{
                id:usernameNullTextInfo
                text:"吗喽的名字不能为空哦~"
                color:"red"
                anchors.top: username.bottom
                anchors.topMargin: 5
                font.bold: true
                anchors.left: parent.left
                anchors.leftMargin: 38
                visible:false
            }
            ComponentInput{
                id:username
                //中间居中
                title: "请输入吗喽的名字~"
                anchors.top: parent.top
                anchors.topMargin: 30
                anchors.left: parent.left
                anchors.leftMargin: (parent.width-username.width)/2
            }

            Text{
                id:passwordNullTextInfo
                text:"吗喽的暗号不能为空~"
                color:"red"
                anchors.top: password.bottom
                anchors.topMargin: 5
                font.bold: true
                anchors.left: parent.left
                anchors.leftMargin: 38
                visible:false
            }

            Text{
                id:loginErrorInfo
                text:errorInfo
                color:"red"
                anchors.top: password.bottom
                anchors.topMargin: 30
                font.bold: true
                font.pixelSize: 30
                anchors.left: parent.left
                anchors.leftMargin: 38
                visible:true
            }

            ComponentInput{
                title: "请输入吗喽之间的暗号"
                anchors.left: parent.left
                anchors.leftMargin: (parent.width-username.width)/2
                anchors.top:username.bottom
                anchors.topMargin: 35
                iconVisible:true
                id:password
                Button{
                    id:loginBtn
                    width: 35
                    height:35
                    anchors.right:  parent.right
                    anchors.rightMargin: 10
                    anchors.verticalCenter: parent.verticalCenter
                    background: Rectangle{
                        border.color: "#dcdcdc"
                        border.width: 0.5
                        id:loginBtnRectangle
                        radius:90
                        color:"#ffffff"
                        MouseArea{
                            anchors.fill: parent;
                            hoverEnabled: true;
                            onEntered: {    //鼠标移入
                                loginBtn.icon.color = "#474e5b"
                                //背景色
                                loginBtnRectangle.color ="#f5f7f9";
                            }
                            onExited: {
                                //移出icon颜色
                                loginBtn.icon.color = "#a9a9a9"
                                //移出背景色
                                loginBtnRectangle.color ="#ffffff";

                            }
                            onClicked: {
                                console.log("用户点击登录")
                                if(username.text==""){
                                    console.log("用户名或密码不能为空")
                                    usernameNullTextInfo.visible=true
                                     return
                                }
                                if(password.text==""){
                                    console.log("用户名或密码不能为空")
                                    passwordNullTextInfo.visible=true
                                    return
                                }
                                //登录请求

                                userLogin(username.text,password.text)
//                                 Http.login({"username":username.text,"password":password.text},function (res){
//                                     console.log(res.data)
//                                     if(res.code===1){
//                                         console.log(res.code)
//                                         console.log("登录成功")
//                                         console.log(res.data.nickname)
// //                                         appWindoow.loding("ChatPage.qml",res.data)
//                                             appWindoow.loding("ZTest.qml",res.data)
// //                                         chatPage.clicked.connect(function() { chatPage.user = res.data })
// //                                        chatPage.setValue()
//                                     }else{
//                                         errorInfo=res.msg
//                                         console.log("登录失败")

//                                     }
//                                 })
                            }

                        }
                    }
                    icon{
                        width:35
                        height:35
                        color:"#828790"
                        source: "qrc:/images/youjiantou"
                    }
                }

            }




        }
        Rectangle{
            id:usernamefrom1
            anchors.bottom:  parent.Bottom
//            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
            //                    anchors.fill: parent
            height: parent.height*0.33
            width: parent.width
            color:"#ffffff"
        }









}
